package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.ProductCategory;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author XiaoHong
 * @description 物资来源接口i
 * @date 2022/2/16
 */
@Api(tags = "物资来源接口")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;
    //http://www.localhost:8989/business/supplier/findSupplierList?pageNum=1&pageSize=10&name=&contact=1
    //显示所有物资来源列表（带分页）
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,
             Supplier supplier  //实际上传过来的几个过滤条件用实体类接受了；
    ){
        PageVO<SupplierVO> supplierListPage = supplierService.findSupplierList(pageNum,pageSize,supplier);
        return ResponseBean.success(supplierListPage) ;
    }

    //http://www.localhost:8989/business/supplier/edit/33
    //点击物资来源修改按钮进行显示指定分类数据
    @GetMapping("/edit/{supplierId}")
    public ResponseBean<Supplier> edit(@PathVariable Long supplierId){
        Supplier supplier = supplierService.edit(supplierId);
        return ResponseBean.success(supplier);
    }

    //http://www.localhost:8989/business/supplier/update/23
    //物资来源编辑界面点击修改确认
    @PutMapping("/update/{supplierId}")
    public ResponseBean update(@RequestBody Supplier supplier,
                               @PathVariable Long supplierId){

        supplierService.update(supplier,supplierId);
        return ResponseBean.success();
    }

    //删除物资来源数据
    @DeleteMapping("/delete/{supplierId}")
    public ResponseBean delete(@PathVariable Long supplierId){

        supplierService.delete(supplierId);
        return ResponseBean.success();
    }

    //添加物资来源数据
    @PostMapping("/add")
    public ResponseBean add(@Validated @RequestBody Supplier supplier){
        supplierService.add(supplier);
        return ResponseBean.success();
    }

    //加载来源数据
//    http://www.localhost:8989/business/supplier/findAll
@GetMapping("/findAll")
public ResponseBean<List<Supplier>> findAll(){
    List<Supplier> all = supplierService.findAll();
    return ResponseBean.success(all) ;
}

}
